<?php
class Data_Model_LoaiDaoTaoMapper extends Data_Model_DataMapperAbstract{
	protected static $_instance = null;
	private $_paginator = null;
	
	public function searchById($id)
	{
		$db = $this->getDb();
		$selectLoaidaotao = $db->select()
							   ->from('tbl_loaidaotao')
							   ->where('MaLoaiDaoTao = ?',$id);
		$loaidt = $db->fetchRow($selectLoaidaotao);
		
		return $this->_populate($loaidt);
		
	}
	public function loaidaotaoList()
	{
		$db = $this->getDb();
		$selectLoaidaotao = $db->select()
						 ->from('tbl_loaidaotao');
		$loaidts = $db->fetchAll($selectLoaidaotao);
		
		$loaidaotaoObjArray = array();
		foreach($loaidts as $loaidt)
		{
			$loaidaotaoObjArray[] = $this->_populate($loaidt);
			
		}
		return $loaidaotaoObjArray;
	}
	public function _populate($data)
	{
		$obj = new Data_Model_LoaiDaoTao();
		$obj->setId($data['MaLoaiDaoTao']);
		$obj->setTenloaidt($data['TenLoaiDaoTao']);
		
		return $obj;
	}
	
	protected function _insert(Data_Model_DomainObjectAbstract $obj)
	{
		$db = $this->getDb();
		$data = array(
				'MaLoaiDaoTao' => $obj->getId(),
				'TenLoaiDaotao' => $obj->getTenloaidt()
				);
		$db->insert('tbl_loaidaotao',$data);
	}
	
	protected function _update(Data_Model_DomainObjectAbstract $obj)
	{
		$db = $this->getDb();
		$data = array(
				'MaLoaiDaoTao' => $obj->getId(),
				'TenLoaiDaotao' => $obj->getTenloaidt()
				);
		$where = $db->quoteInto('MaLoaiDaoTao = ?', $obj->getId());
		$db->update('tbl_loaidaotao',$data,$where);
	}
	
	public function _delete($id)
	{
		$db = $this->getDb();
		$where = $db->quoteInto('MaLoaiDaotao = ?',$id);
		$db->delete('tbl_loaidaotao',$where);
	}
	
	public static function getInstance()
	{
		if(null === self::$_instance)
		{
			self::$_instance = new self();
		}
		return self::$_instance;
	}
}